/*
 * CollaborationsUI.java
 *
 * Created on January 17, 2008, 11:54 AM
 */

package dnl.net.netclip;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;

/**
 *
 * @author  daniel
 */
public class CollaborationsUI extends javax.swing.JPanel {
    
    private List<String> addresses = new ArrayList<String>();
    
    /** Creates new form CollaborationsUI */
    public CollaborationsUI() {
        initComponents();
    }
    
    public List<String> getAddresses(){
        return addresses;
    }
    
    public void setAddresses(List<String> addresses) {
		this.addresses = addresses;
	}

	public JButton getExitButton(){
        return doneJB;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        addressesList = new javax.swing.JList();
        addAddressTF = new javax.swing.JTextField();
        addJB = new javax.swing.JButton();
        removeJB = new javax.swing.JButton();
        doneJB = new javax.swing.JButton();

        jScrollPane1.setViewportView(addressesList);

        addJB.setText("Add");
        addJB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addJBActionPerformed(evt);
            }
        });

        removeJB.setText("Remove");
        removeJB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeJBActionPerformed(evt);
            }
        });

        doneJB.setText("Done");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(addAddressTF, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE))
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(doneJB, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(addJB, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(removeJB, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))
                .addGap(40, 40, 40))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(addJB)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(removeJB)
                        .addGap(158, 158, 158)
                        .addComponent(doneJB)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(addAddressTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(40, 40, 40))))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void addJBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addJBActionPerformed
        addresses.add(addAddressTF.getText());
        addressesList.setListData(addresses.toArray());
    }//GEN-LAST:event_addJBActionPerformed

    private void removeJBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeJBActionPerformed
        Object[] selectedValues = addressesList.getSelectedValues();
        for (Object object : selectedValues) {
            addresses.remove(object);
        }
    }//GEN-LAST:event_removeJBActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField addAddressTF;
    private javax.swing.JButton addJB;
    private javax.swing.JList addressesList;
    private javax.swing.JButton doneJB;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton removeJB;
    // End of variables declaration//GEN-END:variables
    
}
